package com.orjl.networkj;

import android.content.Context;

import io.reactivex.observers.DisposableObserver;

/**
 * 版权：易金 版权所有
 * <p>
 * 作者：suntinghui
 * <p>
 * 创建日期：2019/5/20 0020 16:02
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
public abstract class BaseObserverObject<T> extends DisposableObserver<BaseResponseObjectModel<T>> {


    private Context context;

    public BaseObserverObject(Context context) {
        this.context = context.getApplicationContext();
    }

    @Override
    public void onNext(BaseResponseObjectModel<T> tBaseResponseModel) {

        if (tBaseResponseModel.isSuccess() && tBaseResponseModel.getResult() != null) {
            onSuccess(tBaseResponseModel.getResult());
        } else {
            onFailure(String.valueOf(tBaseResponseModel.getCode()), tBaseResponseModel.getMsg());
        }


    }

    @Override
    public void onError(Throwable e) {
        onFailure("-1", e.toString());
    }

    @Override
    public void onComplete() {

    }


    public abstract void onSuccess(T t);

    public void onFailure(String code, String msg) {

    }
}
